# -*- coding: utf-8 -*-

import random
import string


def random_demo():
    # 生成0到1之间的随机浮点数
    print(random.random())

    min_int = 1
    max_int = 10
    # 生成min到max之间的随机整数
    print(random.randint(min_int, max_int))

    print(random.randrange(start=0, stop=11, step=2))

    print(random.uniform(1.1, 2.2))

    letters = string.ascii_letters[:10]
    # 随机抽样
    print(random.choice(letters))

    # 随机排序
    letter_list = list(letters)
    random.shuffle(letter_list)
    print(letter_list)

    # 随机采样
    print(random.sample(string.ascii_letters, 8))
    pass


def generate_password():
    """生成密码:生成包括数字，小写字母，大写字母，标点符号的8位随机密码"""

    n = 8
    m = 4
    # 数字个数
    digit_count = random.randint(1, n - (m - 1))
    lower_count = random.randint(1, n - (m - 2) - digit_count)
    upper_count = random.randint(1, n - (m - 3) - digit_count - lower_count)
    other_count = n - digit_count - lower_count - upper_count

    # 随机采样
    digit = random.sample(string.digits, digit_count)
    lower = random.sample(string.ascii_lowercase, lower_count)
    upper = random.sample(string.ascii_uppercase, upper_count)
    other = random.sample(string.punctuation, other_count)

    result = []
    result.extend(digit)
    result.extend(lower)
    result.extend(upper)
    result.extend(other)
    # 随机排序
    random.shuffle(result)
    print(''.join(result))

    pass


if __name__ == '__main__':

    for i in range(10):
        generate_password()
        pass
    pass
